package com.ll.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ll.dao.UserCheckService;
import javax.servlet.annotation.WebServlet;

@WebServlet("/UserCheckServlet")
public class UserCheckServlet extends  HttpServlet
{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2591102412228257835L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		System.out.println("in UserCheckServlet ... ");
		
		checkCord(req, resp);
	}
	
	/**
	 * ajax检查数据库中所需信息是否重复
	 */
	private void checkCord(HttpServletRequest req, HttpServletResponse resp)
	{
		String cord = req.getParameter("username");
		try
		{
			boolean flag = UserCheckService.isExist(cord);
			if (flag)
			{
				resp.getWriter().write("exist");
			}
			else
			{
				resp.getWriter().write("notexist");
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	
}
